package org.calzz.rpc.envelope;

import org.calzz.jajb.annotation.Converter;

/**
 * Regardless of the HTTP method used to make the remote procedure call, the
 * response body MUST be a JSON Object that carries the following properties or
 * members.
 * 
 * @author Marek Brodziak <marek.brodziak@gmail.com>
 * @author Piotr Pejas <piotr.pejas@gmail.com>
 * @since Mar 6, 2008
 */
public class JsonResponse {

	private Object id;
	private JsonInvocationError error;
	private Object result;
	private String version;

	/**
	 * @return OPTIONAL. This MUST be the same value as that of the id member of
	 *         Procedure Call object to which the response corresponds. This
	 *         member is maintained for backward compatibility with version 1.0
	 *         of the specification where it was used to correlate a response
	 *         with its request. If the id member was present on the request,
	 *         then the server MUST repeat it verbatim on the response.
	 */
	@Converter(DummyConverter.class)
	public Object getId() {
		return id;
	}

	/**
	 * @param id OPTIONAL. This MUST be the same value as that of the id member
	 *            of Procedure Call object to which the response corresponds.
	 *            This member is maintained for backward compatibility with
	 *            version 1.0 of the specification where it was used to
	 *            correlate a response with its request. If the id member was
	 *            present on the request, then the server MUST repeat it
	 *            verbatim on the response.
	 */
	public void setId(Object id) {
		this.id = id;
	}

	/**
	 * @return REQUIRED on success. The value that was returned by the procedure
	 *         upon a successful invocation. This member MUST be entirely
	 *         omitted in case there was an error invoking the procedure.
	 */
	public Object getResult() {
		return result;
	}

	/**
	 * @param result REQUIRED on success. The value that was returned by the
	 *            procedure upon a successful invocation. This member MUST be
	 *            entirely omitted in case there was an error invoking the
	 *            procedure.
	 */
	public void setResult(Object result) {
		this.result = result;
	}

	/**
	 * @return REQUIRED on error. An Object containing error information about
	 *         the fault that occured before, during or after the call. This
	 *         member MUST be entirely omitted if there was no error.
	 */
	public JsonInvocationError getError() {
		return error;
	}

	/**
	 * @param error REQUIRED on error. An Object containing error information
	 *            about the fault that occured before, during or after the call.
	 *            This member MUST be entirely omitted if there was no error.
	 */
	public void setError(JsonInvocationError error) {
		this.error = error;
	}

	/**
	 * @return REQUIRED. A String specifying the version of the JSON-RPC
	 *         protocol to which the client conforms. An implementation
	 *         conforming to this specification MUST use the exact String value
	 *         of "1.1" for this member. The absence of this member can
	 *         effectively be taken to mean that the remote server implement
	 *         version 1.0 of the JSON-RPC protocol.
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * @param version REQUIRED. A String specifying the version of the JSON-RPC
	 *            protocol to which the client conforms. An implementation
	 *            conforming to this specification MUST use the exact String
	 *            value of "1.1" for this member. The absence of this member can
	 *            effectively be taken to mean that the remote server implement
	 *            version 1.0 of the JSON-RPC protocol.
	 */
	public void setVersion(String version) {
		this.version = version;
	}

}
